package com.google.android.material.bottomsheet;

import android.content.Context;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.SlcAlertController;

import com.blankj.utilcode.util.ReflectUtils;

public class AppBottomSheetAlertDialog extends SlcBottomSheetAlertDialog2 {

    public AppBottomSheetAlertDialog(@NonNull Context context) {
        super(context);
    }

    public AppBottomSheetAlertDialog(@NonNull Context context, int theme) {
        super(context, theme);
    }

    protected AppBottomSheetAlertDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onStart() {
        super.onStart();
        // for landscape mode
        BottomSheetBehavior<FrameLayout> behavior = getBehavior();
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }

    public static class AppBuilder extends Builder {

        public AppBuilder(@NonNull Context context) {
            super(context);
        }

        public AppBuilder(@NonNull Context context, int themeResId) {
            super(context, themeResId);
        }

        @NonNull
        @Override
        public SlcBottomSheetAlertDialog2 create() {
            SlcAlertController.AlertParams P = ReflectUtils.reflect(this).field("P").get();
            AppBottomSheetAlertDialog dialog = new AppBottomSheetAlertDialog(getContext(), ReflectUtils.reflect(this).field("mTheme").get());
            P.apply(dialog.mAlert);
            dialog.setCancelable(P.mCancelable);
            if (P.mCancelable) {
                dialog.setCanceledOnTouchOutside(true);
            }

            dialog.setOnCancelListener(P.mOnCancelListener);
            dialog.setOnDismissListener(P.mOnDismissListener);
            if (P.mOnKeyListener != null) {
                dialog.setOnKeyListener(P.mOnKeyListener);
            }

            return dialog;
        }
    }
}